<?php
namespace App\Domain\Appfc114;
use Illuminate\Database\Capsule\Manager as DB;

class QueryCommon
{

    //过滤表字段数据
    public function FilterField($table, $data)
    {
        $table = $table;
        $Field = DB::select("select COLUMN_NAME from information_schema.COLUMNS where table_name = '$table'");

        foreach ($Field as $item){
            foreach ($item as $k=>$v){
                $Fields[] = $v;
            }
        }
        $temp = array();
        foreach ($data as $k => $v) {
            if (in_array($k, $Fields)) {
                $temp[$k] = $v;
            }
        }
        return $temp;
    }


    public function getRow($sql)
    {
        $result = DB::select($sql);
        return $result;
    }


    function getPaginationDC($page = 1,$pagesize =  30 ,$type="array") {
        $page -= 1;
        $min = 0;
        //$max 指每页取的数据条数
        $max = $pagesize;
        if ($page > 0) {
            $min = $page * $pagesize;
            //$max = ($page + 1) * $pagesize;
        }
        //如果获取全部的话，默认将页数据调整到2000
        if ($page === "all") {
            $max = 2000;
        }
        if($type=="string"){
            $data = $min . "," . $max;
        }else{
            $data["offset"] = $min;
            $data["limit"] = $max;
        }

        return $data;
    }

}
